//
//  MainViewController.swift
//  BookStore
//
//  Created by JinYuXin on 2022/5/12.
//

import UIKit

class MainViewController: UITabBarController {
    
    let defaults = UserDefaults.standard
    var user:String=""
    var bookids=[String]()

    @IBOutlet weak var a: UITabBar!
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //a.items![1].badgeValue="100"

        // Do any additional setup after loading the view.
    }
    override func viewWillAppear(_ animated: Bool) {
        UserShopCarTable.initTable()
        getBookId()
        print(bookids.count)
        UserShopCarTable.GetUserShopCar()
        a.items![1].badgeValue=String(bookids.count)
    }
    

    
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        //guard let booklistviewcontroller = segue.destination as? BookListTableViewController else {return}
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    func getBookId()
    {
        let user = defaults.string(forKey: "userName")!
        let queryuser = UserTable.getUserId(user)
        let userid = String(queryuser![0]["id"]! as! Int)
        let queryuserid = UserShopCarTable.getBookId(userid)
        let userid0 = queryuserid as! [[String:String]]
        bookids=[]
        for book in userid0{
            bookids.append(book["bookid"]!)
        }
    }

}
